﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;

namespace supermarket.method
{
    internal class Classification
    {
        SqlConnection con = new SqlConnection();
        SqlCommand cmd = new SqlCommand();
        SqlDataReader qlddr = null;  //数据缓冲区
        #region
        public void selectlevel (DataGridView dv,string integral1, string integral2, string integral3, string integral4)
        {
            string s;
            int i = 0;
            //1.连接数据库
            Classgetsql sqlcon = new Classgetsql();
            con = sqlcon.getcon();  //数据库已连接并打开
            if (integral1!="" && integral2=="" && integral3=="" && integral4=="") 
            {
                s = "select * from Table_user where  integral <= '" + int.Parse(integral1) + "'";
            }
            else if(integral1 == "" && integral2 != "" && integral3 == "" && integral4 == "")
            {
                s = "select * from Table_user where integral > 1000 and integral <= '" + int.Parse(integral2) + "'";
            }
            else if (integral1 == "" && integral2 == "" && integral3 != "" && integral4 == "")
            {
                s = "select * from Table_user where integral > 3000 and integral <= '" + int.Parse(integral3) + "'";
            }
            else 
            {
                s = "select * from Table_user where integral >'" + int.Parse(integral4) + "'";
            }
            cmd = new SqlCommand(s, con);   //执行SQL语句
            qlddr = cmd.ExecuteReader();   //把sql语句执行结果读取到数据缓冲区qlddr中
            while (qlddr.Read())
            {
                dv[0, i].Value = qlddr[0].ToString();
                dv[1, i].Value = qlddr[1].ToString();
                dv[2, i].Value = qlddr[2].ToString();
                dv[3, i].Value = qlddr[3].ToString();
                dv[4, i].Value = qlddr[4].ToString();
                i++;
            }
            qlddr.Close();
        }
        #endregion
    }
}
